package work14;

import java.util.Scanner;

public class Counter {
    public int  Counter(String inputs, String word){
        int counter = 0;
        String[] temps = new String[inputs.length()];
        for (int i = 0; i < temps.length; i++) {
            temps[i] = inputs.substring(i,i+1);
        }
        for (int j = 0; j < temps.length; j++) {
            if (temps[j].equals(word)){
                counter++;
            }
        }
        return counter;
    }

    public static void main(String[] args) {
        Scanner myinput = new Scanner(System.in);
        Counter cnt = new Counter();
        String myString;
        String myWord;
        System.out.print("请输入一个字符串：");
        myString = myinput.next();
        System.out.print("请输入要查找的字符：");
        myWord = myinput.next();

        int geShu = cnt.Counter(myString,myWord);
        System.out.print("\"" + myString + "\"中包含" + geShu + "个\"" + myWord + "\"。");
    }
}
